// fenxiao/jjCardMember/index.js
const app = getApp();
const utils = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CurrentPage: 1,
    loadingMoreHidden: 1,
    regionId: '',
    layer: 3,
    list: [],
    isBoss: 0//0拓展员1总裁
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.regionId){
      this.data.regionId = options.regionId;
    }
    if(options.layer){
      this.data.layer = options.layer;
    }
    if(options.isBoss){
      this.data.isBoss = options.isBoss;
    }
    this.getCardUserList();
  },

  getCardUserList: function(){
    let that = this;
    let isBoss = that.data.isBoss;
    let parentUid = app.globalData.userInfo.Uid;
    if(isBoss == 1){
      parentUid = 0;
    }
    wx.request({
      url: app.globalData.host + '/api/wxstore/GetCardUserList?parentUid=' + parentUid + '&regionId='+ that.data.regionId + '&layer=' + that.data.layer +'&page=' + that.data.CurrentPage,
      success: function(res){
        if(res.data.Code == 0){
          if(res.data.Data.Items && res.data.Data.Items.length>0){
            let list = res.data.Data.Items;
            if(that.data.CurrentPage != 1){
              let preList = that.data.list;
              list = preList.concat(list);
            }
            for(let i = 0; i < list.length; i++){
              list[i].Avatar = utils.formatAvater(list[i].Avatar,"https://static.711688.net.cn/upload/card/source/");
              list[i].OrderAmount = parseInt(list[i].OrderMoney);
              list[i].Dates = list[i].AddTime.substr(0,10);
              list[i].Times = list[i].AddTime.substr(11,8);
            }
            that.setData({
              list: list,
              loadingMoreHidden: res.data.Data.TotalPages
            })
          }
        }
      },
    })
  },

  loadMore: function(){
    let that = this;
    if(that.data.CurrentPage < that.data.loadingMoreHidden){
      let CurrentPage = that.data.CurrentPage + 1;
      that.setData({
        CurrentPage: CurrentPage
      })
      that.getCardUserList();
    }else{
      return;
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.loadMore();
  }
})